/*
 * XYZCircle.java
 *
 * Created on September 20, 2004, 6:02 PM
 */

package edu.temple.GUS.MMA.Neighborhoods;

/**
 *
 * @author  jeffleon
 */
public class XYZCircle extends XYZNeighborhood{
    
    private int radius;
    
    private boolean filter[][][];

    /** Creates a new instance of XYZCircle */
    public XYZCircle( int r) {

        // Define the x, y and z extend of the neighborhood
        super(r*2+1, r*2+1, r*2+1);
        radius = r;
        
        float distance;
        int kernelXCoord;
        int kernelYCoord;
        int kernelZCoord;
        
        kernelXCoord = r;
        kernelYCoord = r;
        kernelZCoord = r;
        
        // Create a spherical filter
        filter = new boolean[2*radius+1][2*radius+1][2*radius+1];
        
        for (int k=0; k<=2*radius; k++)
            for (int j=0; j<=2*radius; j++)
                for (int i=0; i<=2*radius; i++)
                {
                    distance = (float)Math.sqrt((k - kernelZCoord) * (k - kernelZCoord) + (j - kernelYCoord) * (j - kernelYCoord) + (i - kernelXCoord) * (i - kernelXCoord));
                    if ( distance <= (float)radius)
                        filter[k][j][i] = true;
                    else
                        filter[k][j][i] = false;
                }

    }
    
    public int getRadius() { return radius; }
    public void putRadius(int r) { radius = r; }
    public boolean getFilterElement(int x, int y, int z) { return filter[z][y][x];}
}
